package com.slog_s7;

import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.slog.s7.SLog;

public class MainActivity extends AppCompatActivity {

    private static final String LOG_MSG = "SLog is a so cool Log Tool!";
    private static final String TAG = "SLog";
    private static final String URL_XML = "https://raw.githubusercontent.com/ZhaoKaiQiang/SLog/master/app/src/main/AndroidManifest.xml";
    private static String XML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><!--  Copyright w3school.com.cn --><note><to>George</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note>";
    private static String JSON;
    private static String JSON_LONG;
    private static String STRING_LONG;

    private static Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            SLog.d("Inner Class Test");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();
        handler.sendEmptyMessageDelayed(0, 3000);

    }


    private void initData() {
//        httpClient = new AsyncHttpClient();
        JSON_LONG = getResources().getString(R.string.json_long);
        JSON = getResources().getString(R.string.json);
        STRING_LONG = getString(R.string.string_long);
    }

    public void logTraceStack(View view) {
        TestTraceUtil.testTrace();
    }

    public void logDebug(View view) {
        SLog.debug();
        SLog.debug("This is a debug message");
        SLog.debug("DEBUG", "params1", "params2", this);
    }

    public void log(View view) {
        SLog.v();
        SLog.d();
        SLog.i();
        SLog.w();
        SLog.e();
        SLog.a();
    }

    public void logWithNull(View view) {
        SLog.v(null);
        SLog.d(null);
        SLog.i(null);
        SLog.w(null);
        SLog.e(null);
        SLog.a(null);
    }

    public void logWithMsg(View view) {
        SLog.v(LOG_MSG);
        SLog.d(LOG_MSG);
        SLog.i(LOG_MSG);
        SLog.w(LOG_MSG);
        SLog.e(LOG_MSG);
        SLog.a(LOG_MSG);
    }

    public void logWithTag(View view) {
        SLog.v(TAG, LOG_MSG);
        SLog.d(TAG, LOG_MSG);
        SLog.i(TAG, LOG_MSG);
        SLog.w(TAG, LOG_MSG);
        SLog.e(TAG, LOG_MSG);
        SLog.a(TAG, LOG_MSG);
    }

    public void logWithLong(View view) {
        SLog.d(TAG, STRING_LONG);
    }

    public void logWithParams(View view) {
        SLog.v(TAG, LOG_MSG, "params1", "params2", this);
        SLog.d(TAG, LOG_MSG, "params1", "params2", this);
        SLog.i(TAG, LOG_MSG, "params1", "params2", this);
        SLog.w(TAG, LOG_MSG, "params1", "params2", this);
        SLog.e(TAG, LOG_MSG, "params1", "params2", this);
        SLog.a(TAG, LOG_MSG, "params1", "params2", this);
    }


    public void logWithJson(View view) {
        SLog.json("12345");
        SLog.json(null);
        SLog.json(JSON);
    }

    public void logWithLongJson(View view) {
        SLog.json(JSON_LONG);
    }

    public void logWithJsonTag(View view) {
        SLog.json(TAG, JSON);
    }

    public void logWithFile(View view) {
        SLog.file(Environment.getExternalStorageDirectory(), JSON_LONG);
        SLog.file(TAG, Environment.getExternalStorageDirectory(), JSON_LONG);
        SLog.file(TAG, Environment.getExternalStorageDirectory(), "test.txt", JSON_LONG);
    }

    public void logWithXml(View view) {
        SLog.xml("12345");
        SLog.xml(null);
        SLog.xml(XML);
    }
}
